<template>
	<view class="task-box">
		<view class="top">
			<view>
				<text class="postion-type">[{{ taskData.positionType === '1' ? '国' : '省' }}]</text>
				<text>{{ taskData.projectName ? taskData.projectName : '未关联项目' }}</text>
			</view>
			<view v-if="taskData.taskStatus !== '1'" @click="toPrint">打印</view>
		</view>
		<view @click="toEdit">
			<view class="sub-text">点位编码：{{ taskData.code }}，{{ samplingType }}</view>
			<view class="main sub-text">
				<span>{{`东经: ${taskData.wgs84Longitude}，北纬: ${taskData.wgs84Latitude}`}}</span>
				<u-icon name="arrow-right" size="16"></u-icon>
			</view>
			<view class="sub-text">
				<text>{{`${taskData.provinceName}${taskData.cityName}${taskData.countyName}${taskData.town}${taskData.village}${taskData.team}`}}</text>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex'
	import Util from '@/utils/index.js'
	import API from '@/api/index.js'
	export default {
		props: ['taskData'],
		computed: {
			...mapState({
				userInfo: state => state.user.userInfo
			}),
			samplingType() {
				return Util.DictUtil.getLabel('cj_sampling_type', this.taskData.samplingType);
			},
			isZZ() {
				const regex = /组长/;
				const contains = regex.test(this.userInfo.currentOrgPosition?.positionName);
				return contains
			},
			isZY() {
				const regex = /组员/;
				const contains = regex.test(this.userInfo.currentOrgPosition?.positionName);
				return contains
			}
		},
		methods: {
			async toPrint() {
				uni.navigateTo({
					url: `/pages/print-ct220f/print-ct220f?taskId=${this.taskData.id}`
				})
			},
			async toEdit() {
				// 列表出发，对于 task 而言，只有修改、查看
				// 4 组长 5 组员
				let action = ''
				switch (this.taskData.taskStatus) {
					case '6':
						// 已完成，组员只能看，组长只能看
						action = "watch"
						break;
					case '4':
						// 小组已审核，组员只能看，组长只能回退
						action = this.isZY ? "watch" : this.isZZ ? 'watch' : 'watch'
						break;
					case '7':
						// 组长审核不通过，组员可以改，组长只能看
						action = this.isZY ? "edit" : this.isZZ ? 'watch' : 'watch'
						break;
					case '3':
						// 已上报，组员只能看，组长可以审核
						action = this.isZY ? "watch" : this.isZZ ? 'auth' : 'watch'
						break;
					case '5':
					case '2':
						// 采样中，组员可以改，组长只能看
						action = this.isZY ? "edit" : this.isZZ ? 'watch' : 'watch'
						break;
					case '1':
						// 任务已分配，国控点，组员可以改，组长只能看
						action = this.isZY ? "edit" : this.isZZ ? 'watch' : 'watch'
						break;
				}
				uni.navigateTo({
					url: `/pages/cj-record/cj-record?action=${action}&taskId=${this.taskData.id}`
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.task-box {
		box-sizing: border-box;
		margin-top: 8px;
		background-color: #fff;
		width: calc(100vw - 16px);
		margin-left: 8px;
		border-radius: 6px;
		padding: 5px 10px 10px 10px;

		.top {
			display: flex;
			justify-content: space-between;
			line-height: 26px;
			height: 26px;

			.postion-type {
				color: red;
				margin-right: 3px;
			}
		}

		.sub-text {
			color: gray;
			font-size: 15px;
		}

		.main {
			display: flex;
			justify-content: space-between;
		}

		.foot {
			font-size: 0.9rem;
			display: flex;
		}
	}
</style>